import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  { path: '/', name: 'Home', component: ()=>import('../views/System/Index.vue')},
  { path: '/System/Login', name: 'Login', component: ()=>import('../views/System/Login.vue') },
  { path: '/Payment/PayCallback', name: 'paycb', component: ()=>import('../views/Payment/PayCallback.vue') },  
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  //console.log(this);
  let token = sessionStorage.getItem('token');
  let expires = sessionStorage.getItem('expires');
  if((!token || new Date(expires) < new Date()) && to.path !='/System/Login'){
    next({
      path:'/System/Login',
      query:{
        redirect: to.path
      }
    })
  }else{
    next();
  }
})


export default router
